<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增收费</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;height:100%;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="">
        <input type="hidden" id="staffid" name="staffid" class="input-text">
        <div class="layui-form-item">
            <label class="layui-form-label">缴费人</label>
            <div class="layui-input-block">
                <input type="text" id="namebh" name="namebh" lay-verify="required" placeholder="请输入员工名字或编号" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-input-block">-->
                <!--<select lay-verify="required" lay-search id="sta">-->
                    <!--<option title="请选择"></option>-->
                <!--</select>-->
            <!--</div>-->
        </div>
        <div class="layui-form-item" style="display: none" id="gegege">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-block">
                <input type="text" id="phone" disabled autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item" style="display: none" id="hahaha">
            <label class="layui-form-label">证件号</label>
            <div class="layui-input-block">
                <input type="text" id="sfz" disabled autocomplete="off" class="layui-input">
            </div>
        </div>-->
        <div class="layui-form-item" style="display: none" id="lalala">
            <label class="layui-form-label">到期时间</label>
            <div class="layui-input-block">
                <input type="text" id="dqtime" disabled autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">金额</label>
            <div class="layui-input-block">
                <input type="text" name="money" id="money" lay-verify="required|double" placeholder="请输入金额" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--<div class="layui-form-item" style="">-->
            <!--<label class="layui-form-label">缴费时间</label>-->
            <!--<div class="layui-input-inline">-->
                <!--<input type="text" name="jfTime" id="jftime" lay-verify="required" autocomplete="off" placeholder="请输入缴费时间" class="layui-input">-->
            <!--</div>-->
            <!--&lt;!&ndash;<div class="layui-form-mid layui-word-aux">辅助文字</div>&ndash;&gt;-->
        <!--</div>-->
        <div class="layui-form-inline">
            <label class="layui-form-label">时间段</label>
            <div class="layui-input-inline">
                <input type="text" id="start_time" name="start_time" lay-verify="required" autocomplete="off" placeholder="请输入开始时间" class="layui-input">
            </div>
            <div style="display: inline;">至</div>
            <div class="layui-input-inline">
                <input type="text" id="end_time" name="end_time" lay-verify="required" autocomplete="off" placeholder="请输入结束时间" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="addWuye" lay-submit lay-filter="addWuye">立即收费</button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/js/layui/layui.js"></script>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>

<script>
    $("#namebh").blur(function(){
        var namebh = $("#namebh").val();
        if(namebh==null || namebh==""){
            $("#lalala").css('display','none');
            $("#start_time").val("");
        }else{
            //根据员工姓名或编号查到期时间
            $.ajax({
                url: "/shoufei/selectDqtime?namebh="+namebh
                , type: "GET"
                , contentType: 'application/json'
                // , data: {
                //     'namebh': namebh
                // }
                , success: function (data) {
                    if(data.code==0){
                        $("#lalala").css('display','block');
                        $("#dqtime").val(data.data.dqtime);
                        $("#start_time").val(data.data.dqtime);
                        $("#staffid").val(data.data.id);
                        // $("#hahaha").css('display','block');
                        // $("#sfz").val(data.data.sfz);
                        // $("#gegege").css('display','block');
                        // $("#phone").val(data.data.phone);
                    }else if(data.code==1){
                        layer.msg(data.msg);
                    }else{
                        layer.msg("拒绝访问");
                    }
                }
            });
        }
    })

    layui.use(['form' , 'jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        //自定义验证规则  检测是否为数字
        form.verify({
            double: function(value){
                if(/^\d+$/.test(value)==false && /^\d+\.\d+$/.test(value)==false)
                {
                    return '你输入的不是数字';
                }
            }
        });

        //添加操作
        form.on('submit(addWuye)',function(data){
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            if($("#money").val()==0){
                layer.msg("金额不能为0！");
                return false;
            }
            if(start_time > end_time){
                layer.msg("请输入正确时间");
                return false;
            }else{
                data.field.staffID = $("#staffid").val();
                data.field.ksTime = start_time;
                data.field.jsTime = end_time;
                $.ajax({
                    url:"/shoufei/addshoufei"
                    ,type:"POST"
                    ,contentType: 'application/json'
                    ,data:JSON.stringify(data.field)
                    ,success:function (data) {
                        if(data.code==2){
                            layer.msg(data.data);
                        }else if(data.code==0){
                            layer.close(layer.index);
                            layer.msg('缴费成功');
                            setTimeout(function(){
                                window.location.reload();
                            },1000);
                        }else if(data.code==1){
                            layer.msg('缴费失败');
                        }else{
                            layer.msg("拒绝访问");
                        }
                    }
                    ,error:function () {
                        console.log("ajax error");
                    }
                });
                return false;
            }
        });

        //遍历物业下选框
        // $.ajax({
        //     url: "/staff/selectallstaff"
        //     , type: "POST"
        //     , contentType: 'application/json'
        //     , data: {'status': 1}
        //     , success: function (data) {
        //         $.each(data.data, function (index, item) {
        //             $('#sta').append(new Option(item.name, item.id));// 下拉菜单里添加元素
        //         });
        //         layui.form.render("select");
        //     }
        // });
    });
</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });
    });
</script>
</body>
</html>